package Server.Poker.BJZ;

import java.util.Random;

class tagAnalyseResult {
	int cbFourCount; // 四张数目
	int cbThreeCount; // 三张数目
	int cbLONGCount; // 两张数目
	int cbSignedCount; // 单张数目
	int cbFourLogicVolue[] = new int[1]; // 四张列表
	int cbThreeLogicVolue[] = new int[1]; // 三张列表
	int cbLONGLogicVolue[] = new int[2]; // 两张列表
	int cbSignedLogicVolue[] = new int[5]; // 单张列表
	int cbFourCardData[] = new int[5]; // 四张列表
	int cbThreeCardData[] = new int[5]; // 三张列表
	int cbLONGCardData[] = new int[5]; // 两张列表
	int cbSignedCardData[] = new int[5]; // 单张数目

	public void clear() {
		cbFourCount = 0;
		cbThreeCount = 0;
		cbLONGCount = 0;
		cbSignedCount = 0;
		cbFourLogicVolue[0] = 0;
		cbThreeLogicVolue[0] = 0;
		cbLONGLogicVolue[0] = 0;
		cbLONGLogicVolue[1] = 0;
		for (int i = 0; i < 5; i++) {
			cbSignedLogicVolue[i] = 0;
		}
	}
};

public class GameLogic {
	public static int DRAW = 2; // 和局类型

	// 数值掩码
	public static int LOGIC_MASK_COLOR = (int) 0xF0; // 花色掩码
	public static int LOGIC_MASK_VALUE = 0x0F; // 数值掩码

	public int[] m_byPokerPai;

	int m_byFetchPos;

	public GameLogic() {
		m_byFetchPos = 0;
		m_byPokerPai = new int[52];
	}

	int random(int iMin, int iMax) {
		Random ra = new Random();
		return ra.nextInt(iMax - iMin) + iMin;
	}

	int m_cbCardListData[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, // 方块
																												// A
																												// -
																												// K
			0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, // 梅花
																							// A
																							// -
																							// K
			0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, // 红桃
																							// A
																							// -
																							// K
			0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, // 黑桃
																							// A
																							// -
																							// K
	};

	// 获取数值
	int GetCardValue(int cbCardData) {
		return (int) (cbCardData & LOGIC_MASK_VALUE);
	}

	// 获取花色
	int GetCardColor(int cbCardData) {
		return (int) (cbCardData & LOGIC_MASK_COLOR);
	}

	// 混乱扑克
	void Ruffle(int in_RandCount) {
		m_byFetchPos = 0;

		System.arraycopy(m_cbCardListData, 0, m_byPokerPai, 0, 52);

		int randseed1 = 0;
		int randseed2 = 0;
		for (int i = 0; i < in_RandCount; i++) {
			Random ra1 = new Random();
			Random ra2 = new Random();
			randseed1 += randseed2;
			randseed2 = ra1.nextInt();
			int randPos1 = randseed1 % 52;
			int randPos2 = randseed2 % 52;

			int by1, by2;
			by1 = m_byPokerPai[randPos1];
			by2 = m_byPokerPai[randPos2];
			m_byPokerPai[randPos1] = by2;
			m_byPokerPai[randPos2] = by1;
		}
	}

	void RandCardList(int cbCardBuffer[], int cbBufferCount) {
		// memcpy(cbCardBuffer,m_cbCardListData,cbBufferCount);

		// 混乱准备
		m_byFetchPos = 0;
		System.arraycopy(m_cbCardListData, 0, m_byPokerPai, 0, 52);

		int randseed1 = 0;
		int randseed2 = 0;
		for (int i = 0; i < 1000; i++) {
			randseed1 += randseed2;
			randseed2 = random(1, 10000);
			int randPos1 = randseed1 % 52;
			int randPos2 = randseed2 % 52;
			/*
			 * assert(randPos1 < 52); assert(randPos2 < 52);
			 */
			int by1, by2;
			by1 = m_byPokerPai[randPos1];
			by2 = m_byPokerPai[randPos2];
			m_byPokerPai[randPos1] = by2;
			m_byPokerPai[randPos2] = by1;
		}

		// 混乱扑克
		int bRandCount = 0, bPosition = 0;
		do {
			bPosition = (int) (random(1, 10000) % (52 - m_byFetchPos));
			cbCardBuffer[m_byFetchPos++] = m_byPokerPai[bPosition];
			m_byPokerPai[bPosition] = m_byPokerPai[52 - m_byFetchPos];
		} while (m_byFetchPos < cbBufferCount);

		return;
	}

	// 逻辑数值
	int GetCardLogicValue(int cbCardData) {
		// 扑克属性
		int bCardColor = GetCardColor(cbCardData);
		int bCardValue = GetCardValue(cbCardData);

		// 转换数值
		return (int) ((bCardValue == 1) ? (bCardValue + 13) : bCardValue);
	}

	// 获取类型
	int GetCardType(int cbCardData[], int cbCardCount) {
		// 数据校验

		int cntZero = 0;
		for(int i=0;i<cbCardCount;i++)
		{
			if(cbCardData[i] == 0)
			{
				cntZero++;
			}
		}
		// 变量定义
		boolean cbSameColor = true, bLineCard = true;
		int cbFirstColor = GetCardColor(cbCardData[0]);
		int cbFirstValue = GetCardLogicValue(cbCardData[0]);

		// 牌形分析
		for (int i = 1; i < cbCardCount; i++) {
			// 数据分析
			if (GetCardColor(cbCardData[i]) != cbFirstColor)
				cbSameColor = false;
			if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
				bLineCard = false;

			// 结束判断
			if ((cbSameColor == false) && (bLineCard == false))
				break;
		}

		// 最小同花顺
		if ((bLineCard == false) && (cbFirstValue == 3)) {
			int second = GetCardLogicValue(cbCardData[1]);
			int three = GetCardLogicValue(cbCardData[2]);
	
			if ((2 == second && 14 == three) || (14 == second && 2 == three))
				bLineCard = true;
		}
		// 最小同花顺
		if ((bLineCard == false) && ( cbFirstValue == 14)) {
			int second = GetCardLogicValue(cbCardData[1]);
			int three = GetCardLogicValue(cbCardData[2]);
			
			if ((2 == second && 3 == three) || (3 == second && 2 == three))
				bLineCard = true;
		}

//		// 皇家同花顺
//		if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
//			return Constants.CT_KING_TONG_HUA_SHUN;

		// 顺子类型
		if ((cbSameColor == false) && (bLineCard == true))
		{
			return Constants.CT_SHUN_ZI;
		}

		// 同花类型
		if ((cbSameColor == true) && (bLineCard == false))
		{
			return Constants.CT_TONG_HUA;
		}

		// 同花顺类型
		if ((cbSameColor == true) && (bLineCard == true))
			return Constants.CT_TONG_HUA_SHUN;

		// 扑克分析
		tagAnalyseResult AnalyseResult = new tagAnalyseResult();
		AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

		// 类型判断
		
		
		if (AnalyseResult.cbThreeCount == 1)
			return Constants.CT_THREE_TIAO;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == 1))
			return Constants.CT_ONE_LONG;

		return Constants.CT_SINGLE;
	}

	// 获取类型
		int GetCardTypeZJ(int cbCardData[], int cbCardCount) {
			// 数据校验

			// 变量定义
			boolean cbSameColor = true, bLineCard = true;
			int cbFirstColor = GetCardColor(cbCardData[0]);
			int cbFirstValue = GetCardLogicValue(cbCardData[0]);

			// 牌形分析
			for (int i = 1; i < cbCardCount; i++) {
				// 数据分析
				if (GetCardColor(cbCardData[i]) != cbFirstColor)
					cbSameColor = false;
				if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
					bLineCard = false;

				// 结束判断
				if ((cbSameColor == false) && (bLineCard == false))
					break;
			}

			// 最小同花顺
			if ((bLineCard == false) && (cbFirstValue == 14)) {
				int i = 1;
				for (i = 1; i < cbCardCount; i++) {
					int cbLogicValue = GetCardLogicValue(cbCardData[i]);
					if ((cbFirstValue != (cbLogicValue + i + 8)))
						break;
				}
				if (i == cbCardCount)
					bLineCard = true;
			}

			// 皇家同花顺
			if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
				return Constants.CT_KING_TONG_HUA_SHUN;

			// 顺子类型
			if ((cbSameColor == false) && (bLineCard == true))
				return Constants.CT_SHUN_ZI;

			// 同花类型
			if ((cbSameColor == true) && (bLineCard == false))
				return Constants.CT_TONG_HUA;

			// 同花顺类型
			if ((cbSameColor == true) && (bLineCard == true))
				return Constants.CT_TONG_HUA_SHUN;

			// 扑克分析
			tagAnalyseResult AnalyseResult = new tagAnalyseResult();
			AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

			// 类型判断
			if (AnalyseResult.cbThreeCount == 1)
				return Constants.CT_THREE_TIAO;
			if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == 1))
				return Constants.CT_ONE_LONG;

			return Constants.CT_SINGLE;
		}
	// 排列扑克
	public static void SortCard(int byHandCard[]) {
		for (int i = 0; i < byHandCard.length - 1; i++) {
			for (int j = i; j < byHandCard.length; j++) {
				int x = byHandCard[i];
				int y = byHandCard[j];
				if (x > y) {
					int tempvalue = byHandCard[i];
					byHandCard[i] = byHandCard[j];
					byHandCard[j] = tempvalue;
				}
			}
		}
	}
	void SortCardList(int cbCardData[], int cbCardCount) {
		// 转换数值
		int cbLogicValue[] = new int[52];
		for (int i = 0; i < cbCardCount; i++)
			cbLogicValue[i] = GetCardLogicValue(cbCardData[i]);
		
		// A 2 3  A Îª 1
		if(3 == cbCardCount && (14 == cbLogicValue[0] || 14 == cbLogicValue[1] || 14 == cbLogicValue[2]))
		{
			boolean bTwo = false;
			boolean bTree = false;
			int idx = 0;
			for(int i = 0; i < 3; i ++){
				if(2 == cbLogicValue[i]){
					bTwo = true;
				}
				
				if(3 == cbLogicValue[i]){
					bTree = true;
				}
				
				if(14 == cbLogicValue[i])
				{
					idx = i;
				}
			}
			
			if(bTwo && bTree){
				cbLogicValue[idx] = 1;
			}
		}
		
		// 排序操作
		boolean bSorted = true;
		int cbTempData, bLast = cbCardCount - 1;
		do {
			bSorted = true;
			for (int i = 0; i < bLast; i++) {
				if ((cbLogicValue[i] < cbLogicValue[i + 1])
						|| ((cbLogicValue[i] == cbLogicValue[i + 1]) && (cbCardData[i] < cbCardData[i + 1]))) {
					// 交换位置
					cbTempData = cbCardData[i];
					cbCardData[i] = cbCardData[i + 1];
					cbCardData[i + 1] = cbTempData;
					cbTempData = cbLogicValue[i];
					cbLogicValue[i] = cbLogicValue[i + 1];
					cbLogicValue[i + 1] = cbTempData;
					bSorted = false;
				}
			}
			bLast--;
		} while (bSorted == false);
		if(cbCardData.length == 9){
			int[] card1 = new int [3];
			int[] card2 = new int [3];
			for(int i = 0;i < 2;i++){
				card1[0] = cbCardData[i * 3];
				card1[1] = cbCardData[i * 3 + 1];
				card1[2] = cbCardData[i * 3 + 2];
				card2[0] = cbCardData[(i + 1) * 3];
				card2[1] = cbCardData[(i + 1) * 3 + 1];
				card2[2] = cbCardData[(i + 1) * 3 + 2];
				int ret = this.CompareCard(card1,card2, 3);
				if(ret == 2){
					cbCardData[i * 3] = card2[0];
					cbCardData[i * 3 + 1] = card2[1];
					cbCardData[i * 3 + 2] = card2[2];
					cbCardData[(i + 1) * 3] = card1[0];
					cbCardData[(i + 1) * 3 + 1] = card1[1];
					cbCardData[(i + 1) * 3 + 2] = card1[2];
				}
			}
			for(int i = 2;i > 0;i--){
				card1[0] = cbCardData[i * 3];
				card1[1] = cbCardData[i * 3 + 1];
				card1[2] = cbCardData[i * 3 + 2];
				card2[0] = cbCardData[(i - 1) * 3];
				card2[1] = cbCardData[(i - 1) * 3 + 1];
				card2[2] = cbCardData[(i - 1) * 3 + 2];
				int ret = this.CompareCard(card1,card2, 3);
				if(ret == 1){
					cbCardData[i * 3] = card2[0];
					cbCardData[i * 3 + 1] = card2[1];
					cbCardData[i * 3 + 2] = card2[2];
					cbCardData[(i - 1) * 3] = card1[0];
					cbCardData[(i - 1) * 3 + 1] = card1[1];
					cbCardData[(i - 1) * 3 + 2] = card1[2];
				}
			}
		}
		return;
	}

	//// 排列扑克按照数值大小
	void SortCardByNumList(int cbCardData[], int cbCardCount) {
		// 排序操作
		boolean bSorted = true;
		int cbTempData, bLast = cbCardCount - 1;
		do {
			bSorted = true;
			for (int i = 0; i < bLast; i++) {
				if (cbCardData[i] > cbCardData[i + 1]) {
					// 交换位置
					cbTempData = cbCardData[i];
					cbCardData[i] = cbCardData[i + 1];
					cbCardData[i + 1] = cbTempData;
					bSorted = false;
				}
			}
			bLast--;
		} while (bSorted == false);

		return;
	}
	
	int CompareThreeCard(int cbFirstData[], int cbNextData[], int cbCardCount){
		
		SortCardList(cbFirstData,cbCardCount);
		SortCardList(cbNextData,cbCardCount);
		// 获取类型
		int cbNextType = GetCardType(cbNextData, 5);
		int cbFirstType = GetCardType(cbFirstData, 5);

		// 类型判断
		// 大
		if (cbFirstType > cbNextType)
			return 2;

		// 小
		if (cbFirstType < cbNextType)
			return 1;
		
		// 是否三个相等
		int firstZeroNum = 0;
		int nextZeroNum = 0;
		for(int i=0;i<2;i++){
			int cbNextValue1 = GetCardLogicValue(cbNextData[i]);
			int cbNextValue2 = GetCardLogicValue(cbNextData[i+1]);
			
			int cbFirstValue1 = GetCardLogicValue(cbFirstData[i]);
			int cbFirstValue2= GetCardLogicValue(cbFirstData[i+1]);

			if(cbNextValue1 - cbNextValue2==0){
				nextZeroNum++;
			}
			if(cbFirstValue1 - cbFirstValue2 ==0){
				firstZeroNum++;
			}
			
		}
		
		
		
		if(firstZeroNum ==2&&nextZeroNum!=2){
			return 2;
		}
		if(firstZeroNum !=2&&nextZeroNum==2){
			return 1;
		}
		if(firstZeroNum !=2&&nextZeroNum!=2){
			
			if(firstZeroNum ==1&&nextZeroNum!=1){
				return 2;
			}
			if(firstZeroNum !=1&&nextZeroNum==1){
				return 1;
			}
			if(firstZeroNum !=1&&nextZeroNum!=1){
				
				for(int i=0;i<cbCardCount;i++){
					int numFirst = GetCardLogicValue(cbFirstData[i]);
					int numNext = GetCardLogicValue(cbNextData[i]);
					if(numFirst>numNext){
						return 2;
					}
					if(numFirst<numNext){
						return 1;
					}
				}
				for(int i=0;i<cbCardCount;i++){
					int numFirst = GetCardLogicValue(cbFirstData[i]);
					int numNext = GetCardLogicValue(cbNextData[i]);
					if(numFirst==numNext){
						// 黑桃》红心》梅花》方块
						//牌型花色：方  梅  红  黑
						int colorFirst = (int) Math.floor(cbFirstData[i]/16);
						int colorNext = (int) Math.floor(cbNextData[i]/16);
					
						if(colorFirst>colorNext){
							return 1;
						}
						if(colorFirst<colorNext){
							return 2;
						}
						if(colorFirst==colorNext){
							break;
						}
						
						
					}
				}
				
			}
			
		}
		return 0;
		
	}
	//比鸡特殊牌型///////////////////////////////////////////////////////////////////////////////////////
	//三清  2倍
	int isPaiXingSanQing(int[] cardData[],int cbCount){
		int qingCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if( Constants.CT_TONG_HUA_SHUN == type || Constants.CT_TONG_HUA == type){
				qingCount++;
			}
		}
		if(qingCount == 3){
			return 2;
		}
		return 0;
	}
	//全顺子 12倍
	int isPaiXingQuanShunZi(int[] cardData[],int cbCount){
		int szCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if((type == 3)||(type == 5)||(type == 6)){
				szCount++;
			}
		}
		if(szCount == 3){
			return 12;
		}
		return 0;
	}
	//全同花 12倍
	int isPaiXingQuanTongHua(int[] cardData[],int cbCount){
		int thCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if((type == 4)||(type == 5)||(type == 6)){
				thCount++;
			}
		}
		if(thCount == 3){
			return 12;
		}
		return 0;
	}
	
	//双三条
	int isPaiXingShuangSanTiao(int[] cardData[],int cbCount){
		int stCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if(type == 7){
				stCount++;
			}
		}
		if(stCount == 2){
			return 1;
		}
		return 0;
	}
	
	//ÈýÌõ
	int isPaiXingSanTiao(int[] cardData[],int cbCount){
		int stCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if(type == 7){
				stCount++;
			}
		}
		if(stCount >= 1){
			return 1;
		}
		return 0;
	}

	//È«ÈýÌõ 12±¶
	int isPaiXingQuanSanTiao(int[] cardData[],int cbCount){
		int stCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if(type == 7){
				stCount++;
			}
		}
		if(stCount == 3){
			return 12;
		}
		return 0;
	}

	// 双顺青
	int isPaiXingShuangShunQing(int[] cardData[],int cbCount){
		int szCount = 0;
		for(int i=0;i<cbCount;i++){
			SortCardList(cardData[i],3);
			int type = GetCardType(cardData[i],3);
			if((type == Constants.CT_TONG_HUA_SHUN)||(type == Constants.CT_KING_TONG_HUA_SHUN)){
				szCount++;
			}
		}
		if(szCount == 2){
			return 1;
		}
		return 0;
		
	}

	// 三顺青
	int isPaiXingSanShunQing(int[] cardData[],int cbCount){
		if (12 == isPaiXingQuanTongHua(cardData,cbCount) && 12 == isPaiXingQuanShunZi(cardData,cbCount)) {
			return 12;
		}
		
		return 0;
	}

	// 三连顺
	int isPaiXingSanLianShun(int[] cardData[],int cbCount){
		// 先判断全顺子
		if (12 == isPaiXingQuanShunZi(cardData,cbCount)) {
			// 再判断连续
			int[] tmpArray = new int[cbCount * 3];
			
			int idx = 0;
			for(int i = 0; i < cbCount; i ++ )
			{
				for(int j = 0; j < 3; j++)
				{
					SortCardList(cardData[i], 3);
					if(14 == GetCardLogicValue(cardData[i][2]) && 3 == GetCardLogicValue(cardData[i][0]) && j == 2){
						tmpArray[idx] = 1;
					}else{
						tmpArray[idx] = GetCardLogicValue(cardData[i][j]);
					}
					
					
					
					idx ++;
				}
			}
			// 按照数值排序9张牌
			SortCardByNumList(tmpArray,tmpArray.length);
			
			for(int i = 0; i < tmpArray.length - 1; i ++)
			{
				if(tmpArray[i] + 1 != tmpArray[i+1])
				{
					return 0;
				}
			}
		}else{
			return 0;
		}
		
		return 1;
	}

	// 青连顺
	int isPaiXingLianShunQing(int[] cardData[],int cbCount){
		// 先判断三连顺
		if (1 == isPaiXingSanLianShun(cardData,cbCount) 
			&& 12 == isPaiXingQuanTongHua(cardData,cbCount)
			&& GetCardColor(cardData[0][0]) == GetCardColor(cardData[1][0])
			&& GetCardColor(cardData[1][0]) == GetCardColor(cardData[2][0])) {
			return 1;
		}
		
		return 0;
	}
	//全红  3倍
	int isPaiXingQuanHong(int[] cardData[],int cbCount){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				int colorValue = GetCardColor(cardData[i][j]);
				if((colorValue == 16)||colorValue == 48){
					return 0;
				}
				
		
			}
		}
		return 3;
	}
	
	//全黑 3倍
	int isPaiXingQuanHei(int[] cardData[],int cbCount){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				int colorValue = GetCardColor(cardData[i][j]);
				if((colorValue == 0)||colorValue == 32){
					return 0;
				}
				
		
			}
		}
		return 3;
	}

	//四条12倍(炸弹)
	int isPaiXingSiTiao(int[] cardData[],int cbCount){
		// ÏÈÅÐ¶ÏÊÇ·ñÓÐÈýÌõ
		if(0 == isPaiXingSanTiao(cardData,cbCount)){
			return 0;
		}
		
		int cbCardData[] = new int[9];
		int num = -1;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				num ++;
				cbCardData[num] = cardData[i][j];
			}
		}
		
		for(int i = 0;i < 9;i++){
			cbCardData[i] = GetCardLogicValue(cbCardData[i]);
		}
		SortCard(cbCardData);

		for(int i = 0;i < 6;i++){
			if(cbCardData[i] == cbCardData[i+1] &&
					cbCardData[i] == cbCardData[i+2] &&
					cbCardData[i] == cbCardData[i+3])
				return 12;
		}
			
		return 0;
	}

	//双四条12倍(双炸弹)
	int isPaiXingShuangSiTiao(int[] cardData[],int cbCount){
		// ÏÈÅÐ¶ÏÊÇ·ñÊÇË«ÈýÌõ
		if(0 == isPaiXingShuangSanTiao(cardData,cbCount)){
			return 0;
		}
		
		int cbCardData[] = new int[9];
		int num = -1;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				num ++;
				cbCardData[num] = cardData[i][j];
			}
		}
		
		for(int i = 0;i < 9;i++){
			cbCardData[i] = GetCardLogicValue(cbCardData[i]);
		}
		SortCard(cbCardData);
		
		int szd = 0;
		for(int i = 0;i < 6;i++){
			if(cbCardData[i] == cbCardData[i+1] &&
					cbCardData[i] == cbCardData[i+2] &&
					cbCardData[i] == cbCardData[i+3]){
				i += 3;
				szd++;
			}
		}
		if(szd == 2)
			return 12;
		return 0;
	}

	/////////////////////////////////////////////////////////////////////////////
	// 对比扑克
	int CompareCard(int cbFirstData[], int cbNextData[], int cbCardCount) {
		// 获取类型
		
		int cbFirstType = GetCardType(cbFirstData, cbCardCount);
		int cbNextType = GetCardType(cbNextData, cbCardCount);

		// 类型判断
		// 大
		if (cbFirstType > cbNextType)
			return 2;

		// 小
		if (cbFirstType < cbNextType)
			return 1;

		// 简单类型
		switch (cbFirstType) {
		case Constants.CT_SINGLE: // 单牌
		{
			// 对比数值
			int i = 0;
			for (i = 0; i < cbCardCount; i++) {
				int cbNextValue = GetCardLogicValue(cbNextData[i]);
				int cbFirstValue = GetCardLogicValue(cbFirstData[i]);

				// 大
				if (cbFirstValue > cbNextValue)
					return 2;
				// 小
				else if (cbFirstValue < cbNextValue)
					return 1;
				// 等
				else
					continue;
			}
			// 平
			if (i == cbCardCount) {
				i = 0;
				for (i = 0; i < cbCardCount; i++) {

					int cbFirstColor = GetCardColor(cbFirstData[i]);
					int cbNextColor = GetCardColor(cbNextData[i]);

					// 大
					if (cbFirstColor > cbNextColor)
						return 2;
					// 小
					else if (cbFirstColor < cbNextColor)
						return 1;
					// 等
					else
						continue;
				}
				return 0;
			}
			break;
		}
		case Constants.CT_ONE_LONG: // 对子
		case Constants.CT_THREE_TIAO: // 三条
		{
			// 分析扑克
			tagAnalyseResult AnalyseResultNext = new tagAnalyseResult();
			tagAnalyseResult AnalyseResultFirst = new tagAnalyseResult();
			AnalysebCardData(cbNextData, cbCardCount, AnalyseResultNext);
			AnalysebCardData(cbFirstData, cbCardCount, AnalyseResultFirst);

			// 四条数值
			if (AnalyseResultFirst.cbFourCount > 0) {
				int cbNextValue = AnalyseResultNext.cbFourLogicVolue[0];
				int cbFirstValue = AnalyseResultFirst.cbFourLogicVolue[0];

				// 比较四条
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;

				// 比较单牌
				cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[0];
				cbNextValue = AnalyseResultNext.cbSignedLogicVolue[0];
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;
				else {
					int i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
			}

			// 三条数值
			if (AnalyseResultFirst.cbThreeCount > 0) {
				int cbNextValue = AnalyseResultNext.cbThreeLogicVolue[0];
				int cbFirstValue = AnalyseResultFirst.cbThreeLogicVolue[0];

				// 比较三条
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;

				
				{
					// 比较单牌

					// 散牌数值
					int i = 0;
					for (i = 0; i < AnalyseResultFirst.cbSignedCount; i++) {
						int cbNextValue2 = AnalyseResultNext.cbSignedLogicVolue[i];
						int cbFirstValue2 = AnalyseResultFirst.cbSignedLogicVolue[i];
						// 大
						if (cbFirstValue > cbNextValue2)
							return 2;
						// 小
						else if (cbFirstValue2 < cbNextValue2)
							return 1;
						// 等
						else
							continue;
					}
					if (i == AnalyseResultFirst.cbSignedCount)
					{
						i = 0;
						for (i = 0; i < cbCardCount; i++) {

							int cbFirstColor = GetCardColor(cbFirstData[i]);
							int cbNextColor = GetCardColor(cbNextData[i]);

							// 大
							if (cbFirstColor > cbNextColor)
								return 2;
							// 小
							else if (cbFirstColor < cbNextColor)
								return 1;
							// 等
							else
								continue;
						}
						return 0;
					}
				}
			}

			// 对子数值
			int i = 0;
			for (i = 0; i < AnalyseResultFirst.cbLONGCount; i++) {
				int cbNextValue = AnalyseResultNext.cbLONGLogicVolue[i];
				int cbFirstValue = AnalyseResultFirst.cbLONGLogicVolue[i];
				// 大
				if (cbFirstValue > cbNextValue)
					return 2;
				// 小
				else if (cbFirstValue < cbNextValue)
					return 1;
				// 平
				else
					continue;
			}

			// 比较单牌
			{

				// 散牌数值
				for (i = 0; i < AnalyseResultFirst.cbSignedCount; i++) {
					int cbNextValue = AnalyseResultNext.cbSignedLogicVolue[i];
					int cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[i];
					// 大
					if (cbFirstValue > cbNextValue)
						return 2;
					// 小
					else if (cbFirstValue < cbNextValue)
						return 1;
					// 等
					else
						continue;
				}
				// 平
				if (i == AnalyseResultFirst.cbSignedCount)
				{
					i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
			}
			break;
		}
		case Constants.CT_SHUN_ZI: // 顺子
		case Constants.CT_TONG_HUA_SHUN: // 同花顺
		case Constants.CT_KING_TONG_HUA_SHUN: // 同花顺
		{
			// 数值判断
			int cbNextValue = GetCardLogicValue(cbNextData[0]);
			int cbFirstValue = GetCardLogicValue(cbFirstData[0]);

			boolean bFirstmin = (cbFirstValue == (GetCardLogicValue(cbFirstData[1]) + 9));
			boolean bNextmin = (cbNextValue == (GetCardLogicValue(cbNextData[1]) + 9));
			
			int cbNextValue2 = GetCardLogicValue(cbNextData[1]);
			int cbFirstValue2 = GetCardLogicValue(cbFirstData[1]);
			// A¡¢1¡¢2×îÐ¡
			if(14 == cbFirstValue && (3 == cbFirstValue2 || 2 == cbFirstValue2))
			{
				cbFirstValue = 1;
			}
			// A¡¢1¡¢2×îÐ¡
			if(14 == cbNextValue && (3 == cbNextValue2 || 2 == cbNextValue2))
			{
				cbNextValue = 1;
			}
/*
			// 大小顺子
			if ((cbFirstValue == 14) && (bFirstmin == true) && (bNextmin == false)) {
				return 1;
			}
			// 大小顺子
			else if ((cbNextValue == 14) && (bFirstmin == false) && (bNextmin == true)) {
				return 2;
			}
*/
			if(cbFirstValue > cbNextValue)
			{
				return 2;
			}else if(cbFirstValue < cbNextValue)
			{
				return 1;
			}else {
				// 平
				if (cbFirstValue == cbNextValue)
				{
					if ((cbFirstValue == 14) && (bFirstmin == true) && (bNextmin == false)) {
						return 1;
					}
					if ((cbNextValue == 14) && (bFirstmin == false) && (bNextmin == true)) {
						return 2;
					}
					int i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
				return (cbFirstValue > cbNextValue) ? 2 : 1;
			}
		}
		case Constants.CT_TONG_HUA: // 同花
		{
			int i = 0;
			// 散牌数值
			for (i = 0; i < cbCardCount; i++) {
				int cbNextValue = GetCardLogicValue(cbNextData[i]);
				int cbFirstValue = GetCardLogicValue(cbFirstData[i]);

				if (cbFirstValue == cbNextValue)
					continue;
				return (cbFirstValue > cbNextValue) ? 2 : 1;
			}
			// 平
			if (i == cbCardCount)
			{
				i = 0;
				for (i = 0; i < cbCardCount; i++) {

					int cbFirstColor = GetCardColor(cbFirstData[i]);
					int cbNextColor = GetCardColor(cbNextData[i]);

					// 大
					if (cbFirstColor > cbNextColor)
						return 2;
					// 小
					else if (cbFirstColor < cbNextColor)
						return 1;
					// 等
					else
						continue;
				}
				return 0;
			}
		}
		}

		return 0;
	}

	// 分析扑克
	public void AnalysebCardData(int cbCardData[], int cbCardCount, tagAnalyseResult AnalyseResult) {
		// 设置结果
		AnalyseResult.clear();

		// 扑克分析
		for (int i = 0; i < cbCardCount; i++) {
			// 变量定义
			
			int cbSameCardData[] = { cbCardData[i], 0, 0, 0, 0 };
			int cbLogicValue = GetCardLogicValue(cbCardData[i]);

			if(cbLogicValue != 0)
			{
				int cbSameCount = 1;
				// 获取同牌
				for (int j = i + 1; j < cbCardCount; j++) {
					// 逻辑对比
					if (GetCardLogicValue(cbCardData[j]) != cbLogicValue) {
						break;
					}
					if(cbCardData[j] != 0)
					{
						// 设置扑克
						cbSameCardData[cbSameCount++] = cbCardData[j];					
					}
				}
			


			// 保存结果
			switch (cbSameCount) {
			case 1: // 单张
			{
				AnalyseResult.cbSignedLogicVolue[AnalyseResult.cbSignedCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbSignedCount++;
				break;
			}
			case 2: // 两张
			{
				AnalyseResult.cbLONGLogicVolue[AnalyseResult.cbLONGCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbLONGCardData[(AnalyseResult.cbLONGCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbLONGCount++;
				break;
			}
			case 3: // 三张
			{
				AnalyseResult.cbThreeLogicVolue[AnalyseResult.cbThreeCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbThreeCount++;
				break;
			}
			case 4: // 四张
			{
				AnalyseResult.cbFourLogicVolue[AnalyseResult.cbFourCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbFourCardData[(AnalyseResult.cbFourCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbFourCount++;
				break;
			}
			}

			// 设置递增
			i += cbSameCount - 1;
			}

		}

		return;
	}
	//////////////////////////////////////////////////////////////////////////

}
